| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 118 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 3 | ||
| Bugs | 0 | Features | 0 | 
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* global API */ | ||
| 36 |         .controller('SetupCtrl', ['$scope', '$timeout', '$location', '$rootScope', 'StepsService', function ($scope, $timeout, $location, $rootScope, StepsService) { | ||
| 37 |             $scope.settings = { | ||
| 38 | nextcloud_host: '', | ||
| 39 | nextcloud_username: '', | ||
| 40 | nextcloud_password: '', | ||
| 41 | ignoreProtocol: true, | ||
| 42 | ignoreSubdomain: true, | ||
| 43 | ignorePath: true, | ||
| 44 | generatedPasswordLength: 12, | ||
| 45 | remember_password: true, | ||
| 46 | remember_vault_password: true, | ||
| 47 | vault_password: '', | ||
| 48 | refreshTime: 60, | ||
| 49 |                 default_vault: {}, | ||
| 50 | master_password: '', | ||
| 51 | disableAutoFill: false, | ||
| 52 | disablePasswordPicker: false, | ||
| 53 | disable_browser_autofill: true, | ||
| 54 | debug: false | ||
| 55 | }; | ||
| 56 | $scope.vaults = []; | ||
| 57 | |||
| 58 |             $scope.gogo = function (to) { | ||
| 59 | StepsService.steps().goTo(to); | ||
| 60 | }; | ||
| 61 | |||
| 62 |             $scope.check = { | ||
| 63 |                 server: function (callback) { | ||
| 64 | PAPI.host = $scope.settings.nextcloud_host; | ||
| 65 | PAPI.username = $scope.settings.nextcloud_username; | ||
| 66 | PAPI.password = $scope.settings.nextcloud_password; | ||
| 67 |                     PAPI.getVaults(function (vaults) { | ||
| 68 |                         if (vaults.hasOwnProperty('error')) { | ||
| 69 |                             var errors = API.i18n.getMessage('invalid_response_from_server', [vaults.result.status, vaults.result.statusText]); | ||
| 70 | $scope.errors.push(errors); | ||
| 71 | |||
| 72 | callback(false); | ||
| 73 | } | ||
| 74 |                         else { | ||
| 75 | $scope.vaults = vaults; | ||
| 76 | callback(true); | ||
| 77 | } | ||
| 78 | $scope.$apply(); | ||
| 79 | }); | ||
| 80 | }, | ||
| 81 |                 vault: function (callback) { | ||
| 82 |                     try { | ||
| 83 | PAPI.decryptString($scope.settings.default_vault.challenge_password, $scope.settings.vault_password); | ||
| 84 | callback(true); | ||
| 85 | } | ||
| 86 |                     catch (e) { | ||
| 87 |                         $scope.errors.push(API.i18n.getMessage('invalid_vault_password')); | ||
| 88 | callback(false); | ||
| 89 | } | ||
| 90 | }, | ||
| 91 |                 master: function (callback) { | ||
| 92 |                     if ($scope.settings.master_password.trim() !== '') { | ||
| 93 | callback(true); | ||
| 94 |                     } else { | ||
| 95 |                         $scope.errors.push(API.i18n.getMessage('empty_master_key')); | ||
| 96 | callback(false); | ||
| 97 | } | ||
| 98 | } | ||
| 99 | }; | ||
| 100 | $scope.saving = false; | ||
| 101 |             $scope.next = function () { | ||
| 102 | $scope.saving = true; | ||
| 103 | $scope.errors = []; | ||
| 104 |                 $timeout(function () { | ||
| 105 | var step = StepsService.getCurrent().name; | ||
| 106 | var check = $scope.check[step]; | ||
| 107 |                     if (typeof check === "function") { | ||
| 108 |                         check(function (result) { | ||
| 109 | $scope.saving = false; | ||
| 110 |                             if (result) { | ||
| 111 | $scope.errors = []; | ||
| 112 | $scope.$apply(); | ||
| 113 | StepsService.steps().next(); | ||
| 114 | } | ||
| 115 |                             $timeout(function () { | ||
| 116 | $scope.errors = []; | ||
| 117 | $scope.$apply(); | ||
| 118 | }, 5000); | ||
| 119 | }); | ||
| 120 | } | ||
| 121 |                     else { | ||
| 122 | $scope.saving = false; | ||
| 123 | StepsService.steps().next(); | ||
| 124 | } | ||
| 125 | }, 10); | ||
| 126 | }; | ||
| 127 | |||
| 128 |             $scope.finished = function () { | ||
| 129 | var settings = angular.copy($scope.settings); | ||
| 130 | var master_password = settings.master_password; | ||
| 131 | var master_password_remember = settings.master_password_remember; | ||
| 132 | delete settings.master_password; | ||
| 133 | delete settings.master_password_remember; | ||
| 134 | $scope.saving = true; | ||
| 135 |                 API.runtime.sendMessage(API.runtime.id, { | ||
| 136 | method: "setMasterPassword", | ||
| 137 |                     args: {password: master_password, savePassword: master_password_remember} | ||
| 138 | }) | ||
| 139 |                     .then(function () { | ||
| 140 |                         API.runtime.sendMessage(API.runtime.id, { | ||
| 141 | method: "saveSettings", | ||
| 142 | args: settings | ||
| 143 |                         }).then(function () { | ||
| 144 |                             setTimeout(function () { | ||
| 145 | window.location = '#!/'; | ||
| 146 | $scope.saving = false; | ||
| 147 | }, 1500); | ||
| 148 | }); | ||
| 149 | }); | ||
| 150 | |||
| 151 | |||
| 152 | }; | ||
| 153 | }]); | ||
| 154 | }()); | ||
| 156 |